<?php

class Con_index extends Acan{
	
	public $defaultAct='index';
	function __construct($ainfo=null){
		$this->ctitle = '工具';
		parent::__construct($ainfo=null);
	}
	//
	function Act_test(){
		var_dump($_SERVER);
	}
	function Act_ips(){
		print_r($_SERVER);
	}
	function Act_index(){
		echo '<html><meta http-equiv="refresh" content="0;url='.$this->Aappr.'gzip"></html>';
	}
	function Act_fy(){
		$navtitle = "在线翻译_英译中_中译英";
		if($_POST){
			if($_POST['fy']=='google'){
				$url = "http://translate.google.cn/translate_a/t?client=t&text=".urlencode($_POST['content'])."&hl=".$_POST['hl']."&sl=".$_POST['sl']."&tl=".$_POST['tl'];
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				// 我们在POST数据哦！
				curl_setopt($ch, CURLOPT_GET, 1);
				$output = curl_exec($ch);
				curl_close($ch);
				echo Afun_charset($output,'utf8','text/javascript');
				return;
			}
				$url = "http://fy.iciba.com/interface.php";
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				// 我们在POST数据哦！
				curl_setopt($ch, CURLOPT_POST, 1);
				// 把post的变量加上
				curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
				$output = curl_exec($ch);
				curl_close($ch);
				echo $output;
				return;
		}
		include template('diy:acan/tool_fy');
	}
	function Act_fy2(){
		$this->atitle = "在线翻译_英译中_中译英";
		if($_POST){
			$url = "http://fy.iciba.com/interface.php";
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			// 我们在POST数据哦！
			curl_setopt($ch, CURLOPT_POST, 1);
			// 把post的变量加上
			curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
			$output = curl_exec($ch);
			curl_close($ch);
			echo $output;
			return;
		}
		include_once $this->Atpl();
	}
	//ip检测
	function Act_ip(){
		$this->atitle = "IP地址查询_域名查IP_服务器物理地址查询";
		$ipself = $_SERVER['REMOTE_ADDR'];
		$ips = Afun_ip_info($ipself);
		if ($this->id) {
			$ip = gethostbyname($this->id);
			if($ip){
				$ipr=Afun_ip_info($ip);
			}
		}
		include_once $this->Atpl();
	}
	//gzip检测
	function Act_gzip(){
		$this->model = Afun_db()->model(Acan_table_tool_gzip);
		/*
		“url” //资源网络地址 
		“content_type” //内容编码 
		“http_code” //HTTP状态码 
		“header_size” //header的大小 
		“request_size” //请求的大小 
		“filetime” //文件创建时间 
		“ssl_verify_result” //SSL验证结果 
		“redirect_count” //跳转技术   
		“total_time” //总耗时 
		“namelookup_time” //DNS查询耗时 
		“connect_time” //等待连接耗时 
		“pretransfer_time” //传输前准备耗时 
		“size_upload” //上传数据的大小 
		“size_download” //下载数据的大小 
		“speed_download” //下载速度 
		“speed_upload” //上传速度 
		“download_content_length”//下载内容的长度 
		“upload_content_length” //上传内容的长度   
		“starttransfer_time” //开始传输的时间 
		“redirect_time”//重定向耗时
		*/
		$this->atitle = "网页Gzip信息检测_服务器速度检测";
		if(empty($this->id)){$this->id = 'localhost';}
		//----ip信息获取
		$ip = gethostbyname($this->id);
		$ipr=Afun_ip_info($ip);

		$siteurl = Afun_urldecode($this->id);
		$gzip1= $siteurl?'':'可以检测服务器各项信息.';
		if($siteurl){
			$url=$siteurl;
			if(function_exists('curl_init')){
				$curl = curl_init();
				curl_setopt($curl, CURLOPT_URL, $url);
				curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
				$file_contents = curl_exec($curl);
				curl_setopt($curl, CURLOPT_HEADER, 1);
				curl_setopt($curl, CURLOPT_NOBODY, 1);
				curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate");
				$info = curl_getinfo($curl);
				$data=curl_exec($curl);
				$source = explode("\r\n",$data);
			//显示curl获得的header信息
				curl_close($curl);
			}
			$compressed = strlen(gzcompress($file_contents, 9));
				$aheaders['源文件大小'] = Afun_format_size(strlen($file_contents));
			if(preg_match("/gzip|deflate/i",$data)){
				$aheaders['是否压缩'] = '<font color=green><b>是</b></font>';
				$aheaders['压缩后大小'] = Afun_format_size($compressed);
				$aheaders['压缩率'] = $compressed*100/strlen($file_contents).'</b>%</p>';
			}else{
				$aheaders['是否压缩'] = '<font color=red><b>否</b></font>';
			}
			foreach ($source as $k=>$v){
				$headers[] = explode(': ',$v);
			}

			$content_type = explode('charset=',$info['content_type']);
			if(in_array($content_type[1],array("gbk","gb2312","GB2312","GB-2312"))){
				$file_contents = Afun_charset($file_contents,'utf-8');
			}
			$file_contents = Afun_html_code($file_contents);
			$ainfo['内容编码'] = $info['content_type'];
			
			$ainfo['HTTP状态码'] = $info['http_code'];
			$ainfo['header的大小'] = Afun_format_size($info['header_size']);
			$ainfo['请求的大小'] = Afun_format_size($info['request_size']);
			$ainfo['SSL验证结果'] = $info['ssl_verify_result'];
			$ainfo['跳转技术'] = $info['redirect_count'];
			$ainfo['总耗时'] = $info['total_time'].' 秒';
			$ainfo['DNS查询耗时'] = $info['namelookup_time'].' 秒';
			$ainfo['等待连接耗时'] = $info['connect_time'].' 秒';
			$ainfo['传输前准备耗时'] = $info['pretransfer_time'].' 秒';
			$ainfo['开始传输的时间'] = $info['starttransfer_time'].' 秒';
			$ainfo['下载速度'] = Afun_format_size($info['speed_download']).'/s';
			$ainfo['下载数据的大小'] = Afun_format_size($info['size_download']);
			$ainfo['下载内容的长度'] = $info['download_content_length'];
			$ainfo['重定向耗时'] = $info['redirect_time'];
			$con->url = $this->id;
			$con->ip = Afun_get_ip();
			$con->time = time();
			$this->model->save($con);
			unset($con);
		}
		//查询历史
			$con->select = "url";
			$con->order = "time DESC";
			$con->limit = "10";
			$gzip_list = $this->model->findAll($con);

		include_once $this->Atpl();
	}


}

?>